#include <bits/stdc++.h>

#define eb emplace_back
#define ep emplace
#define fi first
#define se second
#define in read<int>()
#define lin read<ll>()
#define rep(i, x, y) for(int i = (x); i <= (y); i++)
#define per(i, x, y) for(int i = (x); i >= (y); i--)

using namespace std;

using ll = long long;
using db = double;
using pii = pair < int, int >;
using vec = vector < int >;
using veg = vector < pii >;

template < typename T > T read() {
	T x = 0; bool f = 0; char ch = getchar();
	while(!isdigit(ch)) f |= ch == '-', ch = getchar();
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar();
	return f ? -x : x;
}

template < typename T > void chkmax(T &x, const T &y) { x = x > y ? x : y; }
template < typename T > void chkmin(T &x, const T &y) { x = x < y ? x : y; }

const int N = 5e5 + 10;
const int B = 710;
const int T = N / B + 10;

int a[N], pos[N], ans[T][T], b[N], tot, n, m, xl[N], xr[N], bel[N], tcnt[N];
vec pot[N];

int query(int l, int r) {
	int bl = bel[l], br = bel[r], ans = 1;
	if(bl == br) {
		rep(i, l, r) {
			while(pos[i] + ans < pot[a[i]].size() && pot[a[i]][pos[i] + ans] <= r) ans++;
		}
	} else {
		ans = ::ans[bl + 1][br - 1];
		rep(i, l, xr[bl]) while(pos[i] + ans < pot[a[i]].size() && pot[a[i]][pos[i] + ans] <= r) ans++;
		rep(i, xl[br], r) while(pos[i] - ans >= 0 && pot[a[i]][pos[i] - ans] >= l) ans++;
	} return ans;
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("1.in", "r", stdin);
#endif
	n = in; m = in; rep(i, 1, n) a[i] = in, b[i] = a[i];
	rep(i, 1, n) bel[i] = (i - 1) / B + 1, xr[bel[i]] = i;
	rep(i, 1, bel[n]) xl[i] = xr[i - 1] + 1;
	sort(b + 1, b + n + 1); tot = unique(b + 1, b + n + 1) - b - 1; 
	rep(i, 1, n) a[i] = lower_bound(b + 1, b + tot + 1, a[i]) - b, pos[i] = pot[a[i]].size(), pot[a[i]].eb(i); 
	rep(i, 1, bel[n]) {
		rep(j, 1, tot) tcnt[j] = 0;
		int cur = 0;
		rep(j, xl[i], n) {
			if(++tcnt[a[j]] > cur) cur = tcnt[a[j]];
			ans[i][bel[j]] = cur;
		}
	} int ans = 0;
	while(m--) {
		int l = in ^ ans, r = in ^ ans;
		printf("%d\n", ans = query(l, r));
	}
	return 0;
}
